<template>
	<view>
		<!-- <cu-custom bgColor="bg-gradual-blue" :isBack="true">
			<block slot="content">我的收藏({{favlength}})</block>
		</cu-custom> -->
		
		<!-- 加载动画 -->
		<view v-if="pageLoad" class="text-gray padding justify-center flex align-center">
			<u-loading mode="circle" color="#2979ff" size="40"></u-loading>
			<view class="margin-left-sm">加载中...</view>
		</view>
		<view v-if="!pageLoad">
			<view class="text-gray padding justify-center flex" v-if="Object.keys(list).length === 0" ><text>暂无数据</text></view>	
						
			<view class="cu-card case isCard">
				<view class="cu-item shadow" v-for="(item,index) in list" :key="index" @click="goDetail(item._id)">
					<view class="image">
						<image mode="widthFix" :src="item.imgList[0].imgurl"></image>
						<!-- <view class="cu-bar bg-shadeBottom"> <text class="text-cut">{{item.title}}</text></view> -->
					</view>
					<!-- <view class="text-content padding-sm text-cut" style="width:100%;">
						{{item.content}}
					</view> -->
				</view>
			</view>
		
		</view>
		 
	</view>
</template>

<script>
	 
	export default {
		 
		data() {
			return {
				list: [],
				isFirst: true,
				start: 0,
				limit: 50,
				pageLoad: true,
				ssuserid: uni.getStorageSync('userInfo')._id || this.$store.getters.userInfo._id,
				favlength:""
			}
		},
		onLoad:function(){
			this.getPage()
		},
		onPullDownRefresh:function(){			 
			this.getPage()
			uni.stopPullDownRefresh()
		}, 
		onReachBottom:function(){
			this.getList()
		},
		methods: {
			goDetail:function(id){
				uni.navigateTo({
					url:"../topic/show?id="+id
				})
			}, 
			getPage:function(){
				var that = this
				that.pageLoad = true
				uniCloud.callFunction({
					name:"bbs_fav",
					data:{
						cloudAction:"my",
						params:{
							userid: this.ssuserid,
							start: 0,
							limit: this.limit,
						}
					}
				}).then((result)=>{
					// console.log(result)
					var res = result.result.data
					
					that.list = res.list
					that.isFirst = false
					that.start = 0 + that.limit
					that.pageLoad = false
					that.favlength=res.list.length
				})
			},
			getList: function() {
				var that = this
				if(that.start==0 && !that.isFirst){
					return false
				}
				uniCloud.callFunction({
					name: "bbs_fav",
					data: {
						cloudAction: "my",
						params:{
							userid:this.ssuserid,
							start:this.start,
							limit:this.limit,
						}
					}
				}).then((result) => {
					var res=result.result.data
					
					if(that.isFirst){
						that.list = res.list
						that.isFirst = false
					}else{
						// console.log("getList")
						// console.log(that.start,res.list)
						if(res.list.length === 0){
							that.start=0
							return false
						}
						for(var i in res.list){
							that.list.push(res.list[i])
						}
					}
					that.start=that.start+that.limit
				})
			},			
		}
	}
</script>

<style lang="scss" scoped>
 
</style>
